package org.mozhu.zufang.system.privilege.service;

import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.mozhu.mboot.core.data.BaseService;
import org.mozhu.zufang.system.privilege.entity.Role;
import org.mozhu.zufang.system.privilege.repository.RoleRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

/**
 * 角色 - 业务层实现类
 * 
 * @author mozhu
 */
@Transactional
@Service(value = "roleService")
public class RoleServiceImpl extends BaseService<Role, Long> implements RoleService {
	protected RoleRepository getBaseRepository() {
		return (RoleRepository) baseRepository;
	}

	/**
	 * 获取可用的角色列表
	 * 
	 * @param roleIds
	 * @return
	 */
	@Override
	public List<Role> findAvailableRoles(Collection<Long> roleIds) {
		if (CollectionUtils.isEmpty(roleIds)) {
			return Lists.newArrayList();
		}
		return this.getBaseRepository().findAvailableRoles(roleIds);
	}

	@Override
	public List<Long> findDefaultRoleIds() {
		return this.getBaseRepository().findDefaultRoleIds();
	}

	@Override
	public List<Role> findDefaultRoles() {
		return this.getBaseRepository().findDefaultRoles();
	}

}
